﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;

using drawing = System.Drawing;
using opencv = OpenCvSharp;

namespace ViewROI
{
    public class HRegion
    {

        public List<opencv.Point2f> points;

        Rectangle ImagePart;

        public string regionType = "";

        public RotatedRect rotatedRect;

        public Circle circle;

        public Rect rect;

        public string FixCoord;

        public HRegion()
        {
            points = new List<opencv.Point2f>();
        }
        public HRegion(HXLDCont cont)
        {

        }

        public HRegion(int r, int c, int w, int h)
        {
            ImagePart = new Rectangle(c, r, w, h);
            regionType = "rect";
        }

        public Rect GenRectangle1(double row1, double col1, double row2, double col2)
        {
            regionType = "Rect";
            rect = new Rect(new opencv.Point((int)col1, (int)row1), new opencv.Size(col2 - col1, row2 - row1));

            return rect;
        }
        public HRegion Union2(HRegion hRegion)
        {
            return null;
        }

        public void GenRegionLine(double row1, double col1, double row2, double col2)
        {

        }
        public HRegion GenEmptyRegion()
        {
            points = new List<opencv.Point2f>();
            return this;
        }

        public int AreaCenter(out double row, out double col)
        {
            int ac = 0;
            row = 0;
            col = 0;
           if (regionType == "rect")
            {
                ac = ImagePart.Width * ImagePart.Height;
                col = (ImagePart.X + ImagePart.Width) / 2;
                row = (ImagePart.Y + ImagePart.Height) / 2;
            }
            return ac;
        }

        public HRegion Difference(HRegion hRegion)
        {
            return hRegion;
        }

        public Rectangle2 GenRectangle2(double midR, double midC, double phi, double length1, double length2)
        {
            regionType = "RotatedRect";
            rotatedRect = new RotatedRect(new Point2f((float)midC, (float)midR), 
                new Size2f(length1 * 2, length2 * 2), -(float)(phi * 180 / Math.PI));
            return new Rectangle2(midR, midC, phi, length1, length2);
        }

        public Circle GenCircle(double midR, double midC, double radius)
        {
            regionType = "Cicle";
            circle = new Circle(new Point2f((float)midC, (float)midR), (float)radius);
            return circle;
        }

        public string GenFixCoord()
        {
            return "fixCoord";
        }
    }
}
